package com.educatioin.manage.web.system.controller;

import com.educatioin.manage.common.beans.Response;
import com.educatioin.manage.web.system.repository.UserRepository;
import com.educatioin.manage.web.system.request.LoginCheckReq;
import com.educatioin.manage.web.system.response.LoginCheckRsp;
import com.educatioin.manage.web.system.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


/**
 * 登录模块
 */
@RestController
@RequestMapping(value = {"/api/login"}, method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json;charset=UTF-8", consumes = "application/json;charset=UTF-8")
public class LoginController {

    @Autowired
    private LoginService loginService;

    // 登录校验
    @RequestMapping("/authLogin")
    @ResponseBody
    public LoginCheckRsp authLogin(@RequestBody LoginCheckReq loginCheckReq, HttpServletRequest req) {
        return loginService.authLogin(loginCheckReq, req);
    }

    // 登出
    @RequestMapping("/authLogout")
    @ResponseBody
    public Response authLogout(HttpServletRequest req) {
        Response rsp = new Response();

        //清除session
        HttpSession session = req.getSession();
        session.invalidate();

        rsp.setReturnCode(Response.RETURN_SUCCESS_CODE);
        rsp.setReturnMsg("登出成功！");
        return rsp;
    }
}
